package com.wise.service.cms.content.resourcegroup;

import com.wise.entities.content.ResourceGroup;
import com.wise.entities.content.ResourceStatus;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoPageList;
import com.wise.framework.logger.Logger;
import com.wise.framework.restful.PageResultList;
import com.wise.summer.v1.cms.content.resourcegroups.ListResourceGroups;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;


/**
 * @author yubo
 */
@Service
@SummerService
public class ListResourceGroupsService implements SummerServiceBean<ListResourceGroups> {

	private static final Logger log = Logger.getLogger(ListResourceGroupsService.class);

	@Override
	public void sum(ListResourceGroups summer) {
		SqlSelect sql = SqlSelect.selec("*");
		sql.fromClassName(ResourceGroup.class);
		sql.like(!StringUtils.isEmpty(summer.getGroupName()), ResourceGroup._groupName, "%" + summer.getGroupName() + "%");
		sql.eq(StringUtils.isNotBlank(summer.getGroupType()), ResourceGroup._groupType, summer.getGroupType());
		sql.eq(ResourceGroup._status, ResourceStatus.Normal.value());
		sql.eqLang(ResourceGroup._lang);
		PageResultList<ResourceGroup> resourceGroupPageResultList = DaoPageList.s(ResourceGroup.class, sql, summer.getStart(), summer.getLimit());
		summer.setSummerResult(resourceGroupPageResultList);
	}
}
